package com.catjiu.wangEditor.entity;

import lombok.Data;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

@Data
public class DomParagraph extends DomNode {
    private String indent;
    private String lineHeight;
    private String textAlign;
    @Override
    public String getType() {
        return "paragraph";
    }

    private ParagraphAlignment getAlign(){
        if(textAlign==null){
            return null;
        }
        switch (textAlign){
            case "left":
                return ParagraphAlignment.LEFT;
            case "right":
                return ParagraphAlignment.RIGHT;
            case "center":
                return ParagraphAlignment.CENTER;
        }
        return null;
    }

    private int getIndentLeft(){
        return indent==null?0:200*4;
    }

    public void render(XWPFParagraph paragraph) {
        if(textAlign!=null){
            paragraph.setAlignment(getAlign());
        }
        if(indent!=null){
            paragraph.setIndentationLeft(getIndentLeft());
        }
        if(lineHeight!=null){
            paragraph.setSpacingAfterLines(200);
        }
    }
}
